package com.dingreading.cloud.mall.service.impl;

import com.dingreading.cloud.mall.entity.table.ReadstarPayOrderTableDef;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.mall.entity.ReadstarPayOrder;
import com.dingreading.cloud.mall.mapper.ReadstarPayOrderMapper;
import com.dingreading.cloud.mall.service.ReadstarPayOrderService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2025-04-02
 */
@Service
public class ReadstarPayOrderServiceImpl extends BaseServiceImpl<ReadstarPayOrderMapper, ReadstarPayOrder, ReadstarPayOrderTableDef> implements ReadstarPayOrderService {

    @Override
    protected ReadstarPayOrderTableDef getTable() {
        return ReadstarPayOrderTableDef.readstarPayOrder;
    }

    @Override
    public ReadstarPayOrder getByOrderCode(String code) {
        return getMapper().selectOneByCondition(table.orderCode.eq(code));
    }

    @Override
    public boolean payOk(String code, String tradeType, String buyerId, String tradeNo, String payTime, Date callBackTime) {
        QueryCondition condition = QueryCondition.createEmpty();
        condition.and(table.orderCode.eq(code))
                .and(table.payStatus.eq(0));
        return UpdateChain.of(ReadstarPayOrder.class)
                .set(table.tradeNo, tradeNo)
                .set(table.tradeType, tradeType)
                .set(table.payTime, payTime)
                .set(table.buyerId, buyerId)
                .set(table.callBackTime, callBackTime)
                .set(table.payStatus, 1)
                .where(condition)
                .update();
    }
}
